<script setup lang="ts">
// import { routeList } from "@/api/resource-manage";
import { ref, reactive, onMounted } from 'vue'
import { AirDistribution, getAirportCity } from '@/api/home'


const mapData = ref([
  
])

// const  fetchDataApi = async () => {
//     const res = (await routeList()) as any;

//     return {
//       list: res.data.records,
//       total: res.data.total,
//     };
//   }
const airNumObj = ref({
  airportCount: 0,
  debuggingAirportCount: 0,
  runningAirportCount: 0
})
const getAirNumber = async () => {
  const res = await AirDistribution()
  airNumObj.value.debuggingAirportCount = res.data.debuggingAirportCount
  airNumObj.value.airportCount = res.data.airportCount
  airNumObj.value.runningAirportCount = res.data.runningAirportCount
}
// function getProvinceCode(provinceName) {  
//   switch (provinceName) {  
//     case '江苏':  
//       return 'js';  
//     case '河南':  
//       return 'hn';  
//     // 可以添加更多的 case 语句来处理其他省份  
//     default:  
//       return 'gz';  
//   }  
// }  
function getProvinceCode(provinceName) {  
  const provinceMap = {  
    '江苏': 'js',  
    '河南': 'hn',  
    '广东': 'gd',  
    '湖南': 'hunan',  
    '海南': 'hainan',  
    '贵州': 'guizhou',  
    '陕西': 'shanxi',  
  };  

  // 找到第一个匹配的省份  
  const matchedProvince = Object.keys(provinceMap).find(key => provinceName.includes(key));  

  // 返回对应的代码，如果没有匹配则返回默认值  
  return matchedProvince ? provinceMap[matchedProvince] : '';  
}  
const getAirportOfCity = async () => {
  const res=await getAirportCity()

  const originData=res.data

  const transformedData = originData.map(item => {  
  const provinceName = Object.keys(item)[0];  
  const provinceData = item[provinceName];  

  // 根据省份名称映射到目标结构  
  return {  
    name: provinceName.replace('省', ''), // 去掉“省”字  
    airportCount: provinceData.airportCount, // 使用原始数据中的值  
    flyingCount: provinceData.flyingCount ,// 使用原始数据中的值  
    // province: provinceName.includes('江苏') ? 'js' : 'gz' // 使用省份名称判断  
    province: getProvinceCode(provinceName), // 使用映射函数  
      titColor: 'g'

    
  };  
 
});  
  mapData.value = transformedData

}
onMounted(() => {
  // 获取全国机场分布
  getAirNumber()
  // 按照城市获取机场数据
  getAirportOfCity()
})
const handleClick=()=>{

  console.log('111');
  
}
</script>

<template>
  <div class="md-con">
    <!-- 背景 -->
    <div class="bg-animation">
      <div class="bg-1" style="display: flex; justify-content: center; align-items: center">
        <div class="map_wrap">
          <div class="map_con">
            <img src="@/assets/bit-screen/map.png" class="map" alt="" />
            <div
              class="province gz"
              v-for="(item, index) in mapData"
              :key="index"
              :class="item.province"
               @click="handleClick"
            >
              <h3 class="name" :class="item.titColor">{{ item.name }}</h3>
              <div class="province_info">
                <p class="txt">机场总数：{{ item.airportCount }}</p>
                <p class="txt"
                  >飞行中：<span>{{ item.flyingCount }}</span></p
                >
              </div>
            </div>
          </div>
        </div>
      </div>
      <div class="bg-2">
      </div>
    </div>
    <div class="map-box">
      <!-- 全国机场分布情况 -->
      <div class="airport_points">
        <div class="hd">
          <h2 class="tit">全国机场分布情况</h2>
        </div>
        <div class="points_bd">
          <div class="group">
            <img src="@/assets/bit-screen/airport_icon1.png" alt="" />
            <div class="info">
              <h3 class="tit">全部机场</h3>
              <p class="quantity">{{ airNumObj.airportCount }}<span>&nbsp台</span></p>
            </div>
          </div>
          <div class="group">
            <img src="@/assets/bit-screen/airport_icon2.png" alt="" />
            <div class="info">
              <h3 class="tit">任务中机场</h3>
              <p class="quantity">{{ airNumObj.runningAirportCount }}<span>&nbsp台</span></p>
            </div>
          </div>
          <div class="group">
            <img src="@/assets/bit-screen/airport_icon3.png" alt="" />
            <div class="info">
              <h3 class="tit">调试中机场</h3>
              <p class="quantity">{{ airNumObj.debuggingAirportCount }}<span>&nbsp台</span></p>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<style lang="less" scoped>
.md-con {
  position: relative;
  // border: 1px solid blueviolet;
  flex: 1;
  margin: 0 15px;
  overflow: hidden;
  .bg-animation {
    position: absolute;
    z-index: 1;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    .bg-1 {
      position: absolute;
      z-index: 1;
      left: 0;
      top: 0;
      width: 100%;
      height: 100%;
      background: url(@/assets/bit-screen/run_home_bg.png) no-repeat center;
      background-size: 110%;
      .map_wrap {
        flex: 1;
        top: 6%;
        position: relative;
        .map_con {
          position: relative;
          top: 10%;
          position: relative;
          .map {
            width: 90%;
            position: relative;
            left: 10%;
          }
          .province {
            position: absolute;

            &.gz {
              left: 54%;
              top: 67%;
            }
            &.js {
              left: 64%;
              top: 54%;
             
            }
            &.hn {
              left: 60%;
              top: 40%;
            }
            &.hainan {
              left: 58%;
              top: 80%;
            }
            &.hunan {
              left: 60%;
              top: 60%;
            }
           
            &.gd {
              left: 60%;
              top: 70%;
            }
            &.zj {
              left: 40%;
              top: 50%;
            }
           
            &.guizhou {
              left: 50%;
              top: 60%;
            }
            &.shanxi {
              left: 55%;
              top: 40%;
            }
           
           
            &::after {
              position: absolute;
              width: 20px;
              height: 20px;
              content: '';
              background: url(@/assets/bit-screen/mark_b.png) no-repeat center;
              background-size: 100% 100%;
              bottom: -15px;
              margin-left: 5px;
              animation: dot-animation 1s ease-out infinite;

            }
            .name {
              font-family: AlimamaShuHeiTi;
              font-weight: bold;
              font-size: 14px;
              color: #fefefe;
              background: linear-gradient(0deg, #ffffff 0%, #62d6ff 100%);
              -webkit-background-clip: text;
              -webkit-text-fill-color: transparent;
              cursor: pointer;
              &.g {
                color: #fefefe;
                font-weight: bold;
                background: linear-gradient(0deg, #ffffff 0%, #7fe88b 100%);
                -webkit-background-clip: text;
                -webkit-text-fill-color: transparent;
                cursor: pointer;
              }
            }
       
            .province_info {
              position: absolute;
              font-size: 12px;
              width: 120px;
              height: 60px;
              top: -64px;
              left: -50px;
              padding: 10px 10px;
              background: url(@/assets/bit-screen/province_info.png) no-repeat center;
              background-size: 100% 100%;
              cursor: pointer;
            }
           
      
            .txt {
              span {
                font-family: PingFang SC;
                font-weight: 400;
                color: #ffffff;
                background: linear-gradient(0deg, #ffffff 0%, #7fe88b 100%);
                -webkit-background-clip: text;
                -webkit-text-fill-color: transparent;
              }
            }
          }
        }
      }
    }
    .bg-2 {
      position: absolute;
      z-index: 1;
      left: 0;
      top: 0;
      width: 100%;
      height: 100%;
      // background: url(@/assets/bit-screen/map_inner_bg.png) no-repeat center;
      // background-size: 140%;
      // animation: rotate1 60s linear infinite;
    }
  }
  .map-box {
    position: relative;
    width: 100%;
    height: 100%;
    z-index: 10;
    overflow: hidden;
    display: flex;
    flex-direction: column;
  }
  .airport_points {
    width: 55%;
    flex-direction: column;
    margin-top: 15px;
    .hd {
      display: flex;
      justify-content: space-between;
      margin-bottom: 15px;
      color: #daeef9;
      .tit {
        font-weight: bold;
        font-size: 20px;
      }
      .date {
        font-size: 14px;
      }
    }
    .points_bd {
      display: grid;
      width: 100%;
      height: 80px;
      grid-template-columns: repeat(3, 1fr);
      grid-column-gap: 2.5%;
      .group {
        display: grid;
        flex: 1;
        grid-template-columns: 60px auto;
        grid-column-gap: 6px;
        width: 100%;
        height: 100%;
        background: url(@/assets/bit-screen/points_bg.png) no-repeat center;
        background-size: 100% 100%;
        img {
          align-self: center;
          width: 80%;
          margin: 0 auto;
        }
        .info {
          place-self: center start;
          .tit {
            font-size: 15px;
            color: #ffffff;
            text-shadow: 1px 2px 0px rgba(17, 20, 22, 0.22);
            font-style: italic;
            color: #ffffff;
            line-height: 27px;
            text-shadow: 1px 2px 0px rgba(17, 20, 22, 0.22);
            font-style: italic;
            font-family: PingFang SC;
          }
          .quantity {
            font-family: Roboto;
            font-weight: bold;
            font-size: 22px;
            font-style: italic;
            background: linear-gradient(
              80deg,
              rgba(29, 128, 224, 0.64) 0%,
              rgba(255, 255, 255, 0.64) 40%,
              rgba(255, 255, 255, 0.64) 100%
            );
            -webkit-background-clip: text;
            -webkit-text-fill-color: transparent;
            span {
              font-size: 14px;
            }
          }
        }
      }
    }
  }
}
@keyframes rotate1 {
  from {
    transform: rotate(0deg);
  }
  to {
    transform: rotate(360deg);
  }
}
@keyframes rotate2 {
  from {
    transform: rotate(360deg);
  }
  to {
    transform: rotate(0deg);
  }
}

@keyframes dot-animation {
  0% {
    transform: scale(1);
  }
  40% {
    transform: scale(0.8) translate(0, 5px);
  }
  100% {
    transform: scale(1) translate(0, 0);
  }
}
// @media screen and (min-height: 1040px) {
//   .map_wrap .map_con .map {
//     bottom: 10% !important;
//   }
// }
@media screen and (max-width: 1700px) {
  .airport_points {
    width: 65% !important;
  }
}
@media screen and (max-width: 1400px) {
  .airport_points {
    width: 80% !important;
  }
}
</style>
